package com.np.mvvmdemo1;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import java.util.Arrays;
import java.util.List;

public class MainViewModel extends ViewModel {
    private MutableLiveData<List<User>> users = new MutableLiveData<>();

    public MainViewModel() {
        loadUsers();
    }

    public MutableLiveData<List<User>> getUsers() {
        return users;
    }

    private void loadUsers() {
        // 通常这里会是调用 Repository 层的代码
        List<User> dummyUsers = Arrays.asList(new User(1, "Alice"), new User(2, "Bob"));
        users.setValue(dummyUsers);
    }
}
